#CACHE{0}
<?php
    include_spip('functions/pdk_common');
    $cart = pdk_load_class('Alohacart','classes');
    $product_mdl = pdk_load_class('ProductModel','classes');
    
    $cart_data = array();
    $cart_products = $cart->GetProducts();

    if ($_REQUEST) {
		//	Добавление в сессию данные о выборе валюты
		if (_request('act') == 'save_currency_by') {
			$cart->Save_currency_by(_request('select'));
		}
        // Add product
        if (_request('act') == 'add_product' && $id_article = _request('id_article')) {
            $item_quantity = is_numeric($item_quantity = _request('item_quantity'))?$item_quantity:1;

            $request_options = _request('options');
            $options = array();

            if(is_array($request_options)){
                setlocale(LC_ALL, "ru_RU.UTF-8"); // otherwise the regular expression does not work correctly with Cyrillic
                ksort($request_options); // sort by parameters
                foreach($request_options as $key=>$value){
                    $options[$key] = $value;
					// OLD $options[] = $value; // preg_match rules can be added here
				}
            } else {
				$options = $request_options;
			}

            if (lire_config('alohacart/config_consider_quantity')) {
                $product = $product_mdl->select_by_id($id_article);
                $cart_products_count = 0;
                foreach ($cart_products as $array=>$value) {
                    $cart_products_count += $value[1];
                }

                if ($cart_products_count > $product['quantity']) {
					$cart_data['not_enough_products'] = true;
                    exit(json_encode($cart_data));
                }
            }
            $cart->AddProduct($id_article,$item_quantity,$options);
        }

        // Clear cart
        if (_request('act') == 'clear_cart') {
            $cart->ClearCart();
            exit('DeleteOK');
        }
    }

    // By default just return cart data
	//number of items
	$cart_items = $cart->CountItems();
	//number of sku
    $cart_quantity = $cart->CountProducts();

    $cart_price = $cart->CountPrice();
    $cart_data['cart_items'] = $cart_items;
    $cart_data['cart_quantity'] = $cart_quantity;
    $cart_data['cart_price'] = $cart_price;
    $cart_data['options'] = $options;
    exit(json_encode($cart_data));
?>